package system.schedule;

import java.util.TimerTask;
import system.base.InOutCal;


import framework.core.DBConnection;
import framework.core.DBEngine;
import framework.core.DBPreparedStatement;
import framework.core.DBResult;
import framework.core.DateUtil;
import framework.core.LogWriter;

public class CategoryClearTask extends TimerTask {
	
    private static boolean isRunning = false;
	public void run() {
		 if (!isRunning) {
	            myRun();
	        } else {
	            System.out.println("-----------------------------");
	        }
		
	}
	
	private void myRun() {
    	isRunning = true;
    	DBPreparedStatement db = null;
    	DBConnection con = null;
    	try {
			con = DBConnection.open(false);
			con.setAutoCommit(false);
			String sql = "update t_product_type set status=0 where product_id in (select product_id from t_product_storage  group by product_id having sum(product_count)=0) and status=1 and product_type='11' ";
			db =con.prepareStatement(sql);
			db.executeUpdate();
			con.commit();
		} catch (Exception e) {
			try {
				con.rollback();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
            try {
            	if(db!=null){
            		db.close();
            	}
                if (con != null){
                    con.close();
                }
                
            } catch (Exception e) {
                e.printStackTrace();
            }
            isRunning = false;
        }
      
	}

}
